function [] = sendCommand(whichBoat, command, varargin)

defaultSpeed = 1;
defaultPrecision = 5;

assert((whichBoat==1) || (whichBoat==2) || (whichBoat == 3), ...
    'Bad boat selection, needs to be 1, 2, or 3.\n');

switch whichBoat
    case 1
        boatIP = '192.168.1.101';
    case 2
        boatIP = '192.168.1.102';
    case 3
        boatIP = '192.168.1.103';
end

username = 'actuv';
password = 'CMU-actuv';
path = 'boats code/New Boats Code/';
commandPath = 'boats code/New Boats Code/Commands/';


switch command
    case 'goToWaypoint'
        assert(nargin >= 4, 'Args should be (boat, command, lat, lon, [precision, speedScale]');
        assert(nargin <= 6, 'Args should be (boat, command, lat, lon, [precision, speedScale]');
        switch nargin
            case 4
                lat = (varargin{1});
                lon = (varargin{2});
                precision = defaultPrecision;
                speed = defaultSpeed;
                           
            case 5                
                lat = (varargin{1});
                lon = (varargin{2});
                precision = (varargin{3});
                speed = defaultSpeed;                
            case 6
                lat = (varargin{1});
                lon = (varargin{2});
                precision = (varargin{3});
                speed = (varargin{4});
        end
        
        urlread(['http://' boatIP '/cgi-bin/serverScript.pl'], 'GET', {'command', command, 'args', ...
            ['[' num2str(lat) ', ' num2str(lon) ', ' num2str(precision) ', ' num2str(speed) ']']});
%         fid = fopen('mission.txt', 'w');
%         fprintf(fid, 'goToWaypoint\t[%f, %f, %f, %f]\n', lat, lon, precision, speed);
%         fclose(fid);
%         sftp_simple_put(boatIP, username, password, 'mission.txt', commandPath);
%         delete('mission.txt');
    case 'goToHeading'
        assert(nargin >= 3, 'Args should be (boat, command, desHeading, (speed)');
        assert(nargin <= 4, 'Args should be (boat, command, desHeading, (speed)');
        switch nargin
            case 3
                desHeading = (varargin{1});
                speed = defaultSpeed;
            case 4
                desHeading = (varargin{1});
                speed = (varargin{2});
        end
       
        urlread(['http://' boatIP '/cgi-bin/serverScript.pl'], 'GET', {'command', command, 'args', ...
            ['[' num2str(desHeading) ', ' num2str(speed) ']']});
        
%         fid = fopen('mission.txt', 'w');
%         fprintf(fid, 'goToHeading\t[%f, %f]\n', desHeading, speed);
%         fclose(fid);
%         sftp_simple_put(boatIP, username, password, 'mission.txt', commandPath);
%         delete('mission.txt');
    case 'halt'
        assert(nargin == 2, 'No args for halt.');
        urlread(['http://' boatIP '/cgi-bin/serverScript.pl'], 'GET', {'command', command});
%         fid = fopen('mission.txt', 'w');
%         fprintf(fid, 'halt\n');
%         fclose(fid);
%         sftp_simple_put(boatIP, username, password, 'mission.txt', commandPath);
%         delete('mission.txt');
    case 'goAtSpeed'
        assert(nargin >= 3, 'Args should be (boat, command, lat, lon, [speed]');
        assert(nargin <= 6, 'Args should be (boat, command, lat, lon, [speed]');
        switch nargin
            case 4
                lat = (varargin{1});
                lon = (varargin{2});
                speed = 1750; % default speed
                           
            case 5                
                lat = (varargin{1});
                lon = (varargin{2});
                speed = (varargin{3});            
        end
        urlread(['http://' boatIP '/cgi-bin/serverScript.pl'], 'GET', {'command', command, 'args', ...
            ['[' num2str(lat) ', ' num2str(lon) ', ' num2str(speed) ']']});
%         fid = fopen('mission.txt', 'w');
%         fprintf(fid, 'goAtSpeed\t[%f, %f, %f]\n', lat, lon, speed);
%         fclose(fid);
%         sftp_simple_put(boatIP, username, password, 'mission.txt', commandPath);
%         delete('mission.txt');
    case 'goHeadingSpeed'
        assert(nargin == 4, 'Args should be (boat, command, heading, speed');
        switch nargin
            case 4
                heading = (varargin{1});
                speed = (varargin{2});      
        end
        urlread(['http://' boatIP '/cgi-bin/serverScript.pl'], 'GET', {'command', command, 'args', ...
            ['[' num2str(heading) ', ' num2str(speed) ']']});
%         fid = fopen('mission.txt', 'w');
%         fprintf(fid, 'goAtHeadingSpeed\t[%f, %f]\n', heading, speed);
%         fclose(fid);
%         sftp_simple_put(boatIP, username, password, 'mission.txt', commandPath);
%         delete('mission.txt');
    case 'goHeadingSpeedMixed'
        assert(nargin == 4, 'Args should be (boat, command, heading, speed');
        switch nargin
            case 4
                heading = (varargin{1});
                speed = (varargin{2});      
        end
        urlread(['http://' boatIP '/cgi-bin/serverScript.pl'], 'GET', {'command', command, 'args', ...
            ['[' num2str(heading) ', ' num2str(speed) ']']});
%         fid = fopen('mission.txt', 'w');
%         fprintf(fid, 'goAtHeadingSpeedMixed\t[%f, %f]\n', heading, speed);
%         fclose(fid);
%         sftp_simple_put(boatIP, username, password, 'mission.txt', commandPath);
%         delete('mission.txt');
    otherwise
        assert(1==0, 'Command not found.');
end


end
        
        
        
